home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-16 | 4.0 KB | 142 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLLocale.cpp
- // Release Version: $ ODF 3 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef SLLOCALE_H
- #include "SLLocale.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
- #include <Script.h>
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment Strings
- #endif
-
- #ifdef FW_BUILD_WIN
- // include for GetCPInfo
- #include <winnls.h>
- #endif
-
- //========================================================================================
- // FW_MacScriptIsSingleByte
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- static FW_Boolean FW_MacScriptIsSingleByte(short script)
- {
- static short gCachedScriptCode = smRoman;
- static long gCachedScriptIsSingleByte = true;
- if (script != gCachedScriptCode)
- {
- gCachedScriptCode = script;
- long flags = GetScriptVariable(script, smScriptFlags);
- gCachedScriptIsSingleByte = (flags & (1L<<smsfSingByte))!=0;
- }
- return gCachedScriptIsSingleByte;
- }
- #endif
-
- //========================================================================================
- // FW_WinCodePageIsSingleByte
- //========================================================================================
-
- #ifdef FW_BUILD_WIN
- FW_Boolean FW_WinCodePageIsSingleByte(short codePage)
- {
- switch (codePage)
- {
- case 874: // Thai - one byte or two???
- return true;
-
- case 932: // Japanese Kanji
- case 936: // Chinese (PRC, Singapore)
- case 949: // Korean
- case 950: // Chinese (Taiwan, Hong Kong)
- case 1200: // Unicode (BMP of ISO 10646)
- return false;
-
- case 1252: // Western Europe - Roman (Latin 1)
- case 1250: // Eastern Europe - Roman
- case 1251: // Eastern Europe - Cyrillic
- case 1253: // Greek
- case 1254: // Turkish
- case 1255: // Hebrew
- case 1256: // Arabic
- case 1257: // Baltic
- return true;
- }
- return true;
- }
- #endif
-
- //========================================================================================
- // FW_WinScriptIsSingleByte
- //========================================================================================
-
- #ifdef FW_BUILD_WIN
- static FW_Boolean FW_WinScriptIsSingleByte(short codePage)
- {
- static short gCachedCodePage = FW_kWinLatin1;
- static short gCachedCodePageIsSingleByte = true; // don't want to make this a long, like gCachedScriptIsSingleByte
- if (codePage != gCachedCodePage)
- {
- gCachedCodePage = codePage;
- CPINFO cpinfo;
- if (::GetCPInfo((UINT)codePage, &cpinfo)) // Get code page info, if available
- gCachedCodePageIsSingleByte = (cpinfo.MaxCharSize == 1);
- else // Error occurred - try a different tack
- gCachedCodePageIsSingleByte = FW_WinCodePageIsSingleByte(codePage);
- }
- return gCachedCodePageIsSingleByte;
- }
- #endif
-
- //========================================================================================
- // FW_LocaleIsSingleByte
- //========================================================================================
-
- FW_Boolean FW_LocaleIsSingleByte(FW_Locale locale)
- {
- #ifdef FW_BUILD_MAC
- return FW_MacScriptIsSingleByte(locale.fScriptCode);
- #elif defined FW_BUILD_WIN
- return FW_WinScriptIsSingleByte(locale.fScriptCode);
- #endif
- }
-
- //========================================================================================
- // FW_CharIsDoubleByte
- //========================================================================================
-
- FW_Boolean FW_CharIsDoubleByte(const char* p, short offset, const FW_Locale& locale)
- {
- FW_Boolean result = false; // assume false, which will be the case for single-byte scripts
-
- #ifdef FW_BUILD_MAC
- if (!FW_LocaleIsSingleByte(locale))
- {
- Ptr textBuf = (Ptr) p;
- short byteType = ::CharacterByteType(textBuf, offset, locale.fScriptCode);
- if (byteType == smFirstByte)
- result = true;
- }
- #endif
- #ifdef FW_BUILD_WIN
- // Assume entire text uses the same code page
- if (!FW_WinScriptIsSingleByte(locale.fScriptCode))
- result = true;
- #endif
-
- return result;
- }
-
-